package net.hn.hnms.biz.project.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.hn.hnms.biz.project.domain.ProjectBudget;
import net.hn.hnms.biz.project.request.ProjectBudgetReq;
import net.hn.hnms.biz.project.vo.ProjectBudgetVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface ProjectBudgetMapper extends BaseMapper<ProjectBudget> {
    @Update("<script>" +
            " update project_budget set  del_flag = '1' " +
            " where project_budget_id in" +
            " <foreach collection=\"list\" item=\"value\" separator=\",\" open=\"(\" close=\")\">\n" +
            "#{value}" +
            "</foreach>" +
            "</script>")
    void updateDeleteByIds(@Param("list") List<String> list);

    @Select("<script>" +
            " select a.*,pi.project_name projectName from (SELECT " +
            " pb.project_budget_id projectBudgetId, " +
            " pb.project_id projectId, " +
            " pb.budget_code budgetCode, " +
            " pb.budget_title budgetTitle, " +
            " pb.budget_date budgetDate, " +
            " pb.remark,pb.create_time createTime,sum(pbd.amount) countBudgetMoney " +
            " FROM " +
            " project_budget pb " +
            " LEFT JOIN project_budget_detail pbd ON pb.project_budget_id = pbd.project_budget_id " +
            " AND pbd.del_flag = '0' " +
            " WHERE " +
            " pb.del_flag = '0' " +
            " <if test='query.mineCode != null and query.mineCode != \"\" '> "+
            " and pb.mine_code = #{query.mineCode} " +
            " </if>"+
            " <if test='query.budgetTitle!= null and query.budgetTitle!= \"\" '>"+
            " and pb.budget_title LIKE CONCAT('%', #{query.budgetTitle}, '%') " +
            " </if>"+
            " GROUP BY " +
            " pb.project_budget_id) a left join project_info pi on a.projectId = pi.project_id and pi.del_flag = '0' where 1=1" +
            " <if test='query.projectName!= null and query.projectName!= \"\" '>"+
            " and pi.project_name LIKE CONCAT('%', #{query.projectName}, '%')" +
            " </if>"+
            " <if test='query.startTime!= null '>"+
            " and a.budgetDate &gt;= #{query.startTime} " +
            " </if>"+
            " <if test='query.endTime!= null '>"+
            " and a.budgetDate &lt;= #{query.endTime} " +
            " </if>"+
            " </script>")
    Page<ProjectBudgetVo> selectPageList(Page<Object> build, @Param("query") ProjectBudgetReq query);
}
